const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const ScheduledEmail = sequelize.define('ScheduledEmail', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    to: {
        type: DataTypes.STRING,
        allowNull: false
    },
    content: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    scheduleTime: {
        type: DataTypes.DATE,
        allowNull: false
    },
    status: {
        type: DataTypes.ENUM('pending', 'sent', 'failed'),
        defaultValue: 'pending'
    },
    attempts: {
        type: DataTypes.INTEGER,
        defaultValue: 0
    }
}, {
    tableName: 'scheduledemails',
    timestamps: true,
    indexes: [
        {
            fields: ['status', 'scheduleTime']
        }
    ]
});

module.exports = ScheduledEmail; 